//
//  NSMutableDictionary+WeakReference.m
//  MFWSdk
//
//  Created by Song Xiaofeng on 13-7-24.
//  Copyright (c) 2013年 Mafengwo Inc. All rights reserved.
//

#import "NSMutableDictionary+WeakReference.h"
#import "WeakReference.h"
#import "LoadableCategory.h"

MAKE_CATEGORIES_LOADABLE(MFWSdk_NSMutableDictionary_WeakReference)

@implementation NSMutableDictionary (WeakReference)

- (void)setWeakObject:(id)anObject forKey:(id <NSCopying>)aKey;
{
    [self setObject:[WeakReference weakReferenceWithObject:anObject] forKey:aKey];
}

- (id)weakObjectForKey:(id)aKey;
{
    WeakReference *weakRef = [self objectForKey:aKey];
    if ([weakRef isKindOfClass:[WeakReference class]])
    {
        return [weakRef nonretainedObjectValue];
    }
    return nil;
}

- (id)weakValueForKey:(NSString*)aKey;
{
    WeakReference *weakRef = [self valueForKey:aKey];
    if ([weakRef isKindOfClass:[WeakReference class]])
    {
        return [weakRef nonretainedObjectValue];
    }
    return nil;
}
@end
